package com.frxuexi.lib_base.net

import android.content.Context
import androidx.room.Room
import androidx.room.RoomDatabase
import com.frxuexi.lib_base.db.ParkDatabase
import com.frxuexi.lib_base.db.RepairDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {

    @Provides
    @Singleton
    fun getApiService():ApiService=RetrofitUtil.retrofit.create(ApiService::class.java)

    @Provides
    @Singleton
    fun initDB(@ApplicationContext context: Context):ParkDatabase{
        return Room.databaseBuilder(context,ParkDatabase::class.java,"park2301.db")
            .allowMainThreadQueries()
            .build()
    }

    @Provides
    @Singleton
    fun getRepairDao(database: ParkDatabase):RepairDao=database.getRepairDao()
}